package com.zhoug.zmui3.input;

import android.content.Context;
import android.util.AttributeSet;

import com.zhoug.common3.utils.LogUtils;
import com.zhoug.zmui3.R;
import com.zhoug.zmui3.group.ZMUILineaLayout;

import androidx.annotation.Nullable;

/**
 * @Author: zhoug
 * @Date: 2024-07-22
 * @Description:
 */
public class ZMUIValueGroup extends ZMUILineaLayout {
    private static final String TAG = ">>>ZMUIValueGroup";
    private static  boolean DEBUG=false;

    private int[] state_error = new int[]{R.attr.zmui_state_error};
    private int[] state_highlight = new int[]{R.attr.zmui_state_highlight};
    private boolean mError;
    private boolean mHighlight;

    public ZMUIValueGroup(Context context) {
        super(context);
    }

    public ZMUIValueGroup(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public ZMUIValueGroup(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }


    public boolean isError() {
        return mError;
    }

    public boolean isHighlight() {
        return mHighlight;
    }

    public void setError(boolean error) {
        if (mError != error) {
            mError = error;
            refreshDrawableState();
        }
    }


    public void setHighlight(boolean highlight) {
        if (mHighlight != highlight) {
            mHighlight = highlight;
            refreshDrawableState();
        }
    }


    @Override
    protected int[] onCreateDrawableState(int extraSpace) {
        final int[] drawableState = super.onCreateDrawableState(extraSpace + 1);


        if(!isEnabled()){
            if (DEBUG) {
                LogUtils.d(TAG, "onCreateDrawableState: enable false");
            }
            return drawableState;
        }
        if (isError()) {
            if (DEBUG) {
                LogUtils.d(TAG, "onCreateDrawableState: error true");
            }
            mergeDrawableStates(drawableState, state_error);
            return drawableState;
        } else if (isHighlight()) {
            if (DEBUG) {
                LogUtils.d(TAG, "onCreateDrawableState: highlight true");
            }
            mergeDrawableStates(drawableState, state_highlight);
            return drawableState;
        }
        return drawableState;
    }


}
